package com.dcd.controller;

import com.dcd.pojo.Information;
import com.dcd.pojo.User;
import com.dcd.pojo.Video;
import com.dcd.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class UserController {

    @Autowired
    private UserService userService;

    /**
     * @param user 用户对象
     * @return
     */
    @RequestMapping("/login")
    public User login(@RequestBody User user) {
        return userService.login(user);
    }

    /**
     * @param user 用户对象
     * @return
     */
    @RequestMapping("/register")
    public String register(@RequestBody User user) {
        return "{\"result\":\"register_" + userService.register(user) + "\"}";
    }

    /**
     * @param user_phone 手机号
     * @return
     */
    @RequestMapping("/select_phone_whether_register")
    public String select_phone_whether_register(@RequestParam String user_phone) {
        return "{\"result\":\"register_phone_" + userService.select_phone_whether_register(user_phone) + "\"}";
    }

    /**
     * 查询微信登录用户是否被添加到数据库
     *
     * @param user_name 用户名
     * @return
     */
    @RequestMapping("/select_we_chat_whether_add")
    public String select_we_chat_whether_add(@RequestParam String user_name) {
        return "{\"result\":\"register_phone_" + userService.select_we_chat_whether_add(user_name) + "\"}";
    }

    /**
     * 添加微信登录用户对象
     *
     * @param user 用户对象
     * @return
     */
    @RequestMapping("/add_we_chat_user")
    public Map<String, Object> add_we_chat_user(@RequestBody User user) {
        return userService.add_we_chat_user(user);
    }
    /* public String add_we_chat_user(@RequestBody User user) {
        return "{\"result\":\"register_phone_" + userService.add_we_chat_user(user) + "\"}";
    }*/


    /**
     * 根据指定用户名查询对象
     *
     * @param user_name 用户名
     * @return
     */
    @RequestMapping("/select_user_by_user_name")
    public User select_user_by_user_name(@RequestParam String user_name) {
        return userService.select_user_by_user_name(user_name);
    }

    /**
     * 根据用户id查询视频集合
     * @param user_id 用户id  y
     * @param
     * @return
     */
    @RequestMapping("/select_videoList_byUserId")
    public Map<String,Object> select_videoList_byUserId(@RequestParam Integer user_id,@RequestParam Integer pageindex){
        return userService.select_videoList_byUserId(user_id,pageindex);
    }

    /**
     *  根据用户id查询所有发布的资讯
     * @param user_id   用户id
     * @return
     */
    @RequestMapping("/select_information_byUserId")
    public Map<String, Object> select_information_byUserId(@RequestParam Integer user_id,@RequestParam Integer pageIndex){
        return userService.select_information_byUserId(user_id,pageIndex);
    }

    /**
     * 检查该粉丝是否存在
     * @param user_id 用户登录的id  y
     * @param cover_user_id   粉丝的id
     * @return
     */
    @RequestMapping("/existsFenSi")
    public int existsFenSi(@RequestParam Integer user_id,@RequestParam Integer cover_user_id){
        return userService.existsFenSi(user_id,cover_user_id);
    }

    /**
     * 检查是否有发布视频
     * @param user_id
     * @return
     */
    @RequestMapping("/existsSelect_videoList_byUserId")
    public int existsSelect_videoList_byUserId(@RequestParam Integer user_id){
         return userService.existsSelect_videoList_byUserId(user_id);
    }

    /**
     * 检查是否有发布资讯
     * @param user_id
     * @return
     */
    @RequestMapping("/existsSelect_information_byUserId")
    public int existsSelect_information_byUserId(@RequestParam Integer user_id){
        return userService.existsSelect_information_byUserId(user_id);
    }
}
